package co.th.bjc.md.helper.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ResourceBundle;

public class ConnectDB {
	private ResourceBundle configBundle;
    private static final String DEFAULT_CONFIG = "conf.config";

	
//	public Connection getConnectionDB(String transaction_id){
//		Connection connection = null;
//		try{			
//			Class.forName(DRIVER).newInstance();
//			connection = (Connection) DriverManager.getConnection(URL + DB + "?characterEncoding=UTF8", USERNAME, PASSWORD);
//			
//		}catch(Exception ex ){
//			connection = null;
//		}
//		return connection;
//	}
	
	public Connection getConnectionDB(){
		configBundle = ResourceBundle.getBundle(DEFAULT_CONFIG);
		String URL = configBundle.getString("URL");
		String DB = configBundle.getString("DB");
		String DRIVER = configBundle.getString("DRIVER");
		String USERNAME = configBundle.getString("USERNAME");
		String PASSWORD = configBundle.getString("PASSWORD");
		Connection connection = null;
		try{			
			Class.forName(DRIVER).newInstance();
			connection = (Connection) DriverManager.getConnection(URL + DB + "?characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull", USERNAME, PASSWORD);
			
		}catch(Exception ex ){
			ex.printStackTrace();
			connection = null;
		}
		return connection;
	}
}
